package Client;

import module.ExamManage;
import module.StudentExam;
import module.StudentManage;

import java.io.IOException;

public class StudentMainPage {

    private static ClientInitClose client;

    public void modifypassword() throws IOException, ClassNotFoundException {

        while (true) {
            System.out.println("请输入账号：");
            String account = ClientScanner.getScanner().next();
            System.out.println("请输入新密码：");
            String password = ClientScanner.getScanner().next();
            System.out.println("请再次确认密码：");
            if (password.equals(ClientScanner.getScanner().next())) {
                client.getOut().writeObject(account + ";" + password);
                if("success".equals(client.getIn().readObject())){
                    System.out.println("修改密码成功");
                    return;
                }else {
                    System.out.println("该账号不存在");
                    return;
                }
            } else {
                System.out.println("两次密码不同，请重新输入：");
            }
        }
    }

    public void studentMainPage(ClientInitClose c,String num) throws IOException {

        client = c;

        while (true) {
            System.out.println("-----学员系统-----");
            System.out.println("  1、修改密码");
            System.out.println("  2、考试模块");
            System.out.println("  0、退出系统");
            int choose = ClientScanner.getScanner().nextInt();
            try {
                switch (choose) {
                    case 1:
                        client.getOut().writeObject("modify");
                        modifypassword();
                        break;
                    case 2:
                        client.getOut().writeObject("exam");
                        StudentExam se = new StudentExam();
                        se.studentExam(client,num);
                        break;
                    case 0:
                        client.getOut().writeObject("1");
                        return;
                    default:
                        break;
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }

    }

}
